package com.books.service.book.impl;

import com.books.mapper.book.EbookMapper;
import com.books.model.entity.book.Ebook;
import com.books.service.book.IEbookService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class EbookServiceImpl implements IEbookService {

    @Autowired(required = false)
    private EbookMapper ebookMapper;

    @Override
    public Ebook getById(Integer id) {
        return ebookMapper.getById(id);
    }

    @Override
    public List<Ebook> loadAll() {
        return ebookMapper.findAll();
    }

    @Override
    public PageInfo<Ebook> index(String title, Integer categoryId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);

        List<Ebook> ebookList = ebookMapper.getAll(title,categoryId);

        PageInfo<Ebook> pageInfo = new PageInfo<>(ebookList);

        return pageInfo;
    }
}
